<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/15 17:40
 */

namespace App\Transformers;

use App\Models\CnDiagnose;
use App\Models\MedicalDiagnose;
use League\Fractal\TransformerAbstract;

class MedicalDiagnoseTransformer extends TransformerAbstract
{
    public function transform(MedicalDiagnose $diagnose)
    {
        if ($diagnose->cnDiagnoses->count()) {
            $types = app('field')->get('diagnose.cn_diagnose');

            $diagnose->cnDiagnoses->map(function (CnDiagnose $cnDiagnose) use ($types) {

                $cnDiagnose->type = $types['type'][$cnDiagnose->type_id];
            });
        }

        return [
            'id'          => $diagnose->id,
            'record_id'   => $diagnose->record_id,
            'diagnose'    => $diagnose->diagnose,
            'cndiagnoses' => $diagnose->cnDiagnoses,
            'remark'      => $diagnose->remark,
            'created_at'  => $diagnose->created_at->toDateTimeString(),
            'updated_at'  => $diagnose->updated_at->toDateTimeString(),
        ];
    }
}